<?php

namespace app\common\model;

use think\Model;

class UserConsumeLog extends Model
{
    // 表名
    protected $name = 'user_consume_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'type_text'
    ];
    
    // 类型列表
    public static $typeList = [
        'vip' => '会员',
        'goods' => '商品',
        'travel' => '文旅',
        'service' => '服务',
        'withdraw' => '提现'
    ];
    
    public function getTypeTextAttr($value, $data)
    {
        return isset(self::$typeList[$data['type']]) ? self::$typeList[$data['type']] : '';
    }
    
    // 关联用户
    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id');
    }
}